package org.ssm.dufy.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.ssm.dufy.dao.IUserDao;
import org.ssm.dufy.entity.User;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2018/2/27.
 */
@Controller
public class UserController {
/*    @Autowired
    private IUserService userService;

    @RequestMapping(value = "/showname", method = RequestMethod.GET)
    public String showUserName(@RequestParam("uid") int uid, HttpServletRequest request, Model model){
        User user = userService.getUserById(uid);
        if(user != null){
            request.setAttribute("name",user.getUserName());
            model.addAttribute("name",user.getUserName());
            return "showName";
        }
        request.setAttribute("error","没有找到该用户!");
        return "error";
    }*/
    @Autowired
    private IUserDao udao;

    @RequestMapping(value = "/showname", method = RequestMethod.GET)
    public String showUserName(@RequestParam("uid") int uid, HttpServletRequest request, Model model){
        User user = udao.selectByPrimaryKey(uid);
        if(user != null){
            request.setAttribute("name",user.getUserName());
            model.addAttribute("name",user.getUserName());
            return "showName";
        }
        request.setAttribute("error","没有找到该用户!");
        return "error";
    }

    @RequestMapping(value = "/deletename" ,method = RequestMethod.GET)
    public int deleteName(@RequestParam("uid") int uid, HttpServletRequest request, Model model){
        int id = udao.deleteByPrimaryKey(uid);
        return id;
    }
}
